package com.io;

import java.io.*;

/**
 * Test--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2019-03-29 12:35
 **/
public class Test {

    public static void main(String[] args) throws IOException {

        File file = new File("aaa.txt");
        if (file.exists() && file.isFile()) {
            System.out.println("文件已存在覆盖");
        } else {
            System.out.println("文件不存在，新建一个文件 ");
        }

        System.out.println("请输入文本内容，以end结束输入");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        FileWriter dos = new FileWriter(file);
        while ((line = br.readLine()) != null) {
            if (line.equals("end")) {
                break;
            }
            dos.write(line+"\r\n");
        }
        dos.flush();

        System.out.println("输出文件内容");
        FileReader fr = new FileReader("aaa.txt");
        BufferedReader br_read = new BufferedReader(fr);
        String read;
        while ((read = br_read.readLine()) != null) {
            System.out.println(read);
        }
        br.close();
    }
}
